package com.EpidemicPrevention.controller;

import com.EpidemicPrevention.pojo.Register;
import com.EpidemicPrevention.service.RegisterServiceImpl;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;


@Controller
@RequestMapping("/RegisterController")
public class RegisterController {
    @Autowired
    private RegisterServiceImpl registerService;

    //    存储用户信息
//    @Param user
//    @return
    @GetMapping("/saveRegister")
    @ResponseBody
    @CrossOrigin
    public JSON saveRegister (Register register) {
        return  registerService.saveRegister(register);
    }

    @GetMapping("/updateRegister")
    @ResponseBody
    @CrossOrigin
    public  JSON updataRegister(Register register){
        return registerService.updateRegister (register);
    }

    @GetMapping("/deleteRegister")
    @ResponseBody
    @CrossOrigin
    public JSON deleteRegister(int r_id) {
        return registerService.deleteRegister (r_id);
    }

    @GetMapping("/queryRegister")
    @ResponseBody
    @CrossOrigin
    public JSON queryRegister(@RequestParam("page") int page, @RequestParam("limit") int limit,
                              @RequestParam("r_audit") String r_audit) {
        JSONObject json = new JSONObject();
        int page1 = page - 1;
        int page2 = page1 * limit;
        json.put("code", 1);
        json.put("msg", "");
        json.put("count", registerService.queryRegister (0, 100,r_audit,null).size());
        json.put("data",registerService.queryRegister(page2, limit,r_audit,null));
        System.out.println(json);
        return json;
    }

}
